// ==========================================================================
// GFast自动生成dao internal操作代码。
// 生成日期：2024-01-05 17:57:11
// 生成路径: internal/app/flow/dao/internal/flow_model.go
// 生成人：gfast
// desc:流程模型
// company:云南奇讯科技有限公司
// ==========================================================================

package internal

import (
	"context"

	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
)

// FlowModelDao is the manager for logic model data accessing and custom defined data operations functions management.
type FlowModelDao struct {
	table   string           // Table is the underlying table name of the DAO.
	group   string           // Group is the database configuration group name of current DAO.
	columns FlowModelColumns // Columns is the short type for Columns, which contains all the column names of Table for convenient usage.
}

// FlowModelColumns defines and stores column names for table flow_model.
type FlowModelColumns struct {
	Id               string // 主键
	Name             string // 流程名称
	FlowType         string // 表单类型
	FlowFormCate     string // 流程表单类别
	Remark           string // 流程描述
	FlowBusinessCate string // 业务表单类别
	Sort             string // 排序
	Status           string // 流程状态
	CreatedAt        string // 创建时间
	UpdatedAt        string // 修改时间
	DeletedAt        string // 删除时间
	CreatedBy        string // 创建人
	UpdatedBy        string // 修改人
}

var flowModelColumns = FlowModelColumns{
	Id:               "id",
	Name:             "name",
	FlowType:         "flow_type",
	FlowFormCate:     "flow_form_cate",
	Remark:           "remark",
	FlowBusinessCate: "flow_business_cate",
	Sort:             "sort",
	Status:           "status",
	CreatedAt:        "created_at",
	UpdatedAt:        "updated_at",
	DeletedAt:        "deleted_at",
	CreatedBy:        "created_by",
	UpdatedBy:        "updated_by",
}

// NewFlowModelDao creates and returns a new DAO object for table data access.
func NewFlowModelDao() *FlowModelDao {
	return &FlowModelDao{
		group:   "default",
		table:   "flow_model",
		columns: flowModelColumns,
	}
}

// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *FlowModelDao) DB() gdb.DB {
	return g.DB(dao.group)
}

// Table returns the table name of current dao.
func (dao *FlowModelDao) Table() string {
	return dao.table
}

// Columns returns all column names of current dao.
func (dao *FlowModelDao) Columns() FlowModelColumns {
	return dao.columns
}

// Group returns the configuration group name of database of current dao.
func (dao *FlowModelDao) Group() string {
	return dao.group
}

// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *FlowModelDao) Ctx(ctx context.Context) *gdb.Model {
	return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}

// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *FlowModelDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
	return dao.Ctx(ctx).Transaction(ctx, f)
}
